package com.hhw.config;


import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

public class MyLocaleResolver implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest  request) {
        //获取请求连接中的语言参数
        String language = request.getParameter("l");

//        System.out.println("====>"+language);

        //获取默认
        Locale locale = Locale.getDefault();
        //判断是否为空，如果不为就用我自己传过来接的值
        if (!StringUtils.isEmpty(language)){
            String[] split = language.split("_");
            //分割数组，国家，地区
            locale=new Locale(split[0], split[1]);

        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {

    }
}
